{include file="common/header"}
<div id="app" v-cloak>
    <div class="el-pane-warp">
		<el-form ref="config" :model="config" label-width="170px">
			<el-form-item label="管理员上传图片限制：">
				<el-input style="max-width: 500px;" v-model="config.admin.ext.image" placeholder="支持上传的文件格式以逗号(,)隔开"></el-input>
				<el-input style="max-width: 150px;" v-model.number="config.admin.size.image">
					<template slot="append">MB</template>
				</el-input>
			</el-form-item>
			<el-form-item label="管理员上传视频限制：">
				<el-input style="max-width: 500px;" v-model="config.admin.ext.video" placeholder="支持上传的文件格式以逗号(,)隔开"></el-input>
				<el-input style="max-width: 150px;" v-model.number="config.admin.size.video">
					<template slot="append">MB</template>
				</el-input>
			</el-form-item>
			<el-form-item label="管理员上传音频限制：">
				<el-input style="max-width: 500px;" v-model="config.admin.ext.audio" placeholder="支持上传的文件格式以逗号(,)隔开"></el-input>
				<el-input style="max-width: 150px;" v-model.number="config.admin.size.audio">
					<template slot="append">MB</template>
				</el-input>
			</el-form-item>
			<el-form-item label="管理员上传文档限制：">
				<el-input style="max-width: 500px;" v-model="config.admin.ext.word" placeholder="支持上传的文件格式以逗号(,)隔开"></el-input>
				<el-input style="max-width: 150px;" v-model.number="config.admin.size.word">
					<template slot="append">MB</template>
				</el-input>
			</el-form-item>
			<el-form-item label="管理员上传其它限制：">
				<el-input style="max-width: 500px;" v-model="config.admin.ext.other" placeholder="支持上传的文件格式以逗号(,)隔开"></el-input>
				<el-input style="max-width: 150px;" v-model.number="config.admin.size.other">
					<template slot="append">MB</template>
				</el-input>
			</el-form-item>
			<el-form-item label="会员上传限制：">
				<el-input style="max-width: 500px;" v-model="config.api.ext.user" placeholder="支持上传的文件格式以逗号(,)隔开"></el-input>
				<el-input style="max-width: 150px;" v-model.number="config.api.size.user">
					<template slot="append">MB</template>
				</el-input>
			</el-form-item>
		</el-form>
		<div class="el-bottom">
			<el-button 
				size="medium"
				:loading="loading" 
				type="primary" 
				icon="el-icon-refresh-right" 
				@click="save()">
				保 存
			</el-button>
		</div>
	</div>
</div>
<script>
	new Vue({
	    el: '#app',
	    data() {
	        return {
	        	url: "config/upload",
	        	config: {:json_encode($config)},
	        	loading: false,
	        }
	    },
	    created() {
        	this.config.api.size.user = this.config.api.size.user / 1024 / 1024;
        	this.config.admin.size.image = this.config.admin.size.image / 1024 / 1024;
        	this.config.admin.size.video = this.config.admin.size.video / 1024 / 1024;
        	this.config.admin.size.audio = this.config.admin.size.audio / 1024 / 1024;
        	this.config.admin.size.word  = this.config.admin.size.word  / 1024 / 1024;
        	this.config.admin.size.other = this.config.admin.size.other / 1024 / 1024;
        },
	    methods: {
	        /**
             * 保存基础配置
             */
	        save() {
	        	let self = this;
	        	let config = JSON.parse(JSON.stringify(self.config));
        		config.api.size.user   = self.config.api.size.user * 1024 * 1024;
	        	config.admin.size.image = self.config.admin.size.image * 1024 * 1024;
	        	config.admin.size.video = self.config.admin.size.video * 1024 * 1024;
	        	config.admin.size.audio = self.config.admin.size.audio * 1024 * 1024;
	        	config.admin.size.word  = self.config.admin.size.word  * 1024 * 1024;
	        	config.admin.size.other = self.config.admin.size.other * 1024 * 1024;
	        	self.loading = true;
	        	request.post(self.url, {config: config}, function(res){
                    self.loading = false;
                    self.$notify({showClose: true, message: res.message, type: res.status});
                });
	        },
	    }
	})
</script>
{include file="common/footer"}